package components;

import java.io.Serializable;
import java.util.Timer;
import java.util.TimerTask;

import org.newdawn.slick.Animation;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import KI.KI;
/**
 * This is the figure the Player can control
 *
 */
public class Bomberman implements Serializable{

	private static final long serialVersionUID = 3L;

	/**
	 * The movement speed of the player
	 */
	public float speed;

	/**
	 * The explosion range of this Player
	 */
	public int range;

	/**
	 * The remaining lifes
	 */
	public int lifes;

	/**
	 * Is true if Player is able to kick a bomb away
	 */
	public boolean kick;

	/**
	 * A reference to the current Item
	 */
	public Item item;

	/**
	 * The coordinates of this Player
	 */
	public float[] position;

	/**
	 * The coordinates of the start position of this bomberman
	 */
	public float[] start;

	/**
	 * All Bombs set by this player
	 */
	public Bomb[] bombs;

	/**
	 * The limit of possible set bombs
	 */
	public int bombLimit;

	/**
	 * The number of actual set bombs
	 */
	public int bombsSet;

	/**
	 * The number of wins in this game 
	 */
	public int wins;

	/**
	 * The icon of this player
	 */
	public Image img;

	/**
	 * The playing id of this player
	 */
	public int id;

	/**
	 * Is used to handle time
	 */
	transient Timer timer = new Timer();

	/**
	 * Explosion time for this player
	 */
	public int time;

	/**
	 * Is true if the player is forced to bomb, because of an item effect
	 */
	public boolean forcedToBomb;

	/**
	 * Is true if player is invincible
	 */
	public boolean invincible;

	/**
	 * Is the current animation of this player
	 */
	public transient Animation animation;

	/**
	 * Is true if player died in this game
	 */
	public boolean dead;

	/**
	 * Is true if player is in revange mode
	 */
	public boolean revange;

	/**
	 * Is true if this bomber is controlled by the computer
	 */
	public boolean com;


	/**
	 * Help variable for the current player
	 */
	public int direction;
	public int di;
	public int bombx;
	public int bomby;
	public boolean bomblay = false;



	/**
	 * The Constructor to create the standardized player
	 * @param position The coordinates of this player
	 * @param id The current id
	 * @param life the current amount of lifes
	 */
	public Bomberman(float[] position, int id, int life){
		this.speed = 0.005f;
		this.range = 2;
		this.lifes = life;
		this.kick = false;
		this.item = null;
		this.position = position;
		this.bombLimit=1;
		this.bombs = new Bomb[this.bombLimit];
		this.bombsSet=0;
		this.wins=0;
		this.id=id;
		this.time=3000;
		this.forcedToBomb=false;
		this.invincible=false;
		this.img=game.Multiplayer.bomberi;
		this.dead=false;
		this.revange=false;
		this.com=false;
		this.direction = 1;

	}

	/**
	 * The Constructor to copy an existing player
	 * @param bomber The bomber to copy from
	 * @param position Set the new position of the new bomber
	 */
	public Bomberman(Bomberman bomber, float[] position){
		this.speed = bomber.speed;
		this.range = bomber.range;
		this.lifes = bomber.lifes;
		this.kick = bomber.kick;
		this.item = bomber.item;
		this.position = position;
		this.start = bomber.start;
		this.bombs = bomber.bombs;
		this.bombLimit=bomber.bombLimit;
		this.bombsSet=bomber.bombsSet;
		this.wins=bomber.wins;
		this.img=bomber.img;
		this.id=bomber.id;
		this.time=bomber.time;
		this.forcedToBomb=bomber.forcedToBomb;
		this.invincible=bomber.invincible;
		this.com=false;
		this.revange=false;
		this.direction = 1;

	}

	/**
	 * This construcotr ist needed for kryonet
	 */

	public Bomberman(){

	}

	/**
	 * Sets the bomb, after checking the requirements
	 */
	public void setBomb(){
		int posx=Math.round(this.position[0]);
		int posy=Math.round(this.position[1]);

		if(this.bombsSet<this.bombLimit && game.Multiplayer.map.field[posy][posx].type.equals("space") && game.Multiplayer.stat.equals("run")){
			game.Multiplayer.map.field[posy][posx].type="bomb";
			game.Multiplayer.map.field[posy][posx]=new Bomb(new float[]{posx, posy}, this, this.time);
			this.bombsSet++;
			bombx	=	posx;
			bomby 	=	posy;
			bomblay =	true;
		}
	}

	/**
	 * Decrease the number of set bombs
	 */
	public void deleteBomb(){
		this.bombsSet--;
	}

	/**
	 * Paint the player, depending on the parameter
	 * @param color decides which color should be used 
	 */

	public void paint(int color){

		if(color==0){
			for(int i = 0; i<4; i++){
				game.Multiplayer.movingDown[this.id].getImage(i).setImageColor(0, 1, 0.2f);
				game.Multiplayer.movingUp[this.id].getImage(i).setImageColor(0, 1, 0.2f);
				game.Multiplayer.movingRight[this.id].getImage(i).setImageColor(0, 1, 0.2f);
				game.Multiplayer.movingLeft[this.id].getImage(i).setImageColor(0, 1, 0.2f);
			}
		}
		else{

			for(int i = 0; i<4; i++){
				game.Multiplayer.movingDown[this.id].getImage(i).setImageColor(1, 0, 0.2f);
				game.Multiplayer.movingUp[this.id].getImage(i).setImageColor(1, 0, 0.2f);
				game.Multiplayer.movingRight[this.id].getImage(i).setImageColor(1, 0, 0.2f);
				game.Multiplayer.movingLeft[this.id].getImage(i).setImageColor(1, 0, 0.2f);
			}
		}

	}

	/**
	 * Paints the figure to it's normal color
	 */
	public void unpaint(){

		for(int i = 0; i<4; i++){
			game.Multiplayer.movingDown[this.id].getImage(i).setImageColor(1, 1, 1);
			game.Multiplayer.movingUp[this.id].getImage(i).setImageColor(1, 1, 1);
			game.Multiplayer.movingRight[this.id].getImage(i).setImageColor(1, 1, 1);
			game.Multiplayer.movingLeft[this.id].getImage(i).setImageColor(1, 1, 1);
		}
	}

	/**
	 * Is called when the player dies.
	 * Decides if figure should be set to its start position or is deleted from the game
	 */
	public void die(){
		this.lifes--;

		if(this.item!=null){
			this.item.finishEffect(this.id);
		}

		if(this.lifes>=0){
			this.position[0]=game.Multiplayer.startpos[this.id][0];
			this.position[1]=game.Multiplayer.startpos[this.id][1];
			this.animation=new Animation(new Image[]{game.Multiplayer.movingDown[this.id].getImage(0)}, 190, false);
			this.animation.stop();
			this.animation.setCurrentFrame(0);
			this.invincible=true;

			this.timer=new Timer();
			this.timer.schedule(new TimerTask() {
				public void run() {
					invincible = false;
				};
			}, 1500);
		}
		else{
			this.animation=game.Multiplayer.die[this.id];
			this.animation.restart();
			this.animation.setLooping(false);
			this.timer=new Timer();
			this.timer.schedule(new TimerTask() {
				public void run() {
					dead=true;
				};
			}, 1500);
		}

	}

	/**
	 * Sets the player back to initial status and sets the lifes
	 * @param lifes Numer of remaining lifes
	 */
	public void noItems(int lifes){
		this.speed = 0.005f;
		this.range = 2;
		this.lifes = lifes;
		this.kick = false;
		this.item = null;
		this.bombLimit=1;
		this.bombsSet=0;
		this.time=3000;
		this.forcedToBomb=false;
		this.invincible=false;
		this.com=false;
		this.revange=false;
	}


	/**
	 * Controls the player through keyboard input 
	 * @param in Input controller of the slick2D engine
	 * @param delta Used to conform the speed
	 */
	public void move(Input in, int delta){

		if(this.com){
			int letzt=0; 

			KI ki = new KI();
			float[] weg = ki.findeWeg(Math.round(this.position[0]), Math.round(this.position[1]), this.bombLimit-this.bombsSet);

			if(Math.round(this.position[0])<(int)weg[0]){
				this.position[0]+=this.speed*delta;
				letzt=1;
			}
			else if(Math.round(this.position[0])>(int)weg[0]){
				this.position[0]-=this.speed*delta;
				letzt=2;
			}
			else if(Math.round(this.position[1])<(int)weg[1]){
				this.position[1]+=this.speed*delta;
				letzt=3;
			}
			else if(Math.round(this.position[1])>(int)weg[1]){
				this.position[1]-=this.speed*delta;
				letzt=4;
			}
			if(Math.round(this.position[0])==(int)weg[0] && Math.round(this.position[1])==(int)weg[1] && weg[2]==1){
				System.out.println("und ich wil eine bombe legen");
				this.setBomb();

				switch (letzt) {
				case 1: this.position[0]-=this.speed*delta;break;
				case 2: this.position[0]+=this.speed*delta;break;
				case 3: this.position[1]-=this.speed*delta;break;
				case 4: this.position[1]+=this.speed*delta;break;

				default: break;
				}
			}
		}
		else{
			if(this.lifes>=0){
				if(in.isKeyDown(Input.KEY_RIGHT)){
					direction = 2;
					this.animation=game.Multiplayer.movingRight[this.id];
					if( this.position[0]+this.speed*delta<game.Multiplayer.map.size-1){ 
						if(game.Multiplayer.map.field[Math.round(this.position[1])][(int)Math.ceil(this.position[0]+this.speed*delta)].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("right", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[0]+=this.speed*delta;
						}

						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("right", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])+1].speedx=0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])+1].speedy=0;
						}
					}
				}
				else if(in.isKeyDown(Input.KEY_LEFT)){
					System.out.println("Eingabe Links");
					direction = 3;
					this.animation=game.Multiplayer.movingLeft[this.id];
					if(this.position[0]-this.speed*delta>0){

						if(game.Multiplayer.map.field[Math.round(this.position[1])][(int)Math.floor(this.position[0]-this.speed*delta)].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("left", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[0]-=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("left", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])-1].speedx=-0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])-1].speedy=0;
						}
					}

				}
				else if(in.isKeyDown(Input.KEY_UP)){
					System.out.println("Eingabe hoch");
					direction = 0;
					this.animation=game.Multiplayer.movingUp[this.id];
					if(this.position[1]-this.speed*delta>0){
						if(game.Multiplayer.map.field[(int) Math.floor(this.position[1]-this.speed*delta)][Math.round(this.position[0])].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("up", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[1]-=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("up", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])-1][Math.round(this.position[0])].speedy=-0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])-1][Math.round(this.position[0])].speedx=0;
						}
					}
				}


				else if(in.isKeyDown(Input.KEY_DOWN)){
					System.out.println("Eingabe runter");
					direction = 1;
					this.animation=game.Multiplayer.movingDown[this.id];
					if(this.position[1]+this.speed*delta<game.Multiplayer.map.size-1){
						if(game.Multiplayer.map.field[(int) Math.ceil(this.position[1]+this.speed*delta)][Math.round(this.position[0])].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("down", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[1]+=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("down", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])+1][Math.round(this.position[0])].speedy=+0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])+1][Math.round(this.position[0])].speedx=0;
						}
					}
				}
				else{
					direction = 4;
					this.animation.stop();
					this.animation.setCurrentFrame(0);
				}

				if(in.isKeyPressed(Input.KEY_SPACE)){
					direction = 5;
					this.setBomb();
				}
			}
		}
	}

	/**
	 * Is used to control Movement in offline multiplayer
	 * @param in Input controller of the slick2D engine
	 * @param delta Used to conform the speed
	 * @param id Decides the controlling keys
	 */
	public void move(Input in, int delta, int id){
		if(id==1){
			if(this.lifes>=0){

				//KI ki = new KI();
				//float[] test = ki.findeWeg(Math.round(this.position[0]), Math.round(this.position[1]), this.bombLimit-this.bombsSet);
				//System.out.println("Gehe am besten zu"+test[0]+" ,"+test[1]);

				if(in.isKeyDown(Input.KEY_RIGHT)){
					direction = 2;
					di = 2;
					this.animation=game.Multiplayer.movingRight[this.id];
					this.animation.start();
					if( this.position[0]+this.speed*delta<game.Multiplayer.map.size-1){ 

						if(game.Multiplayer.map.field[Math.round(this.position[1])][(int)Math.ceil(this.position[0]+this.speed*delta)].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("right", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[0]+=this.speed*delta;
						}

						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("right", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])+1].speedx=0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])+1].speedy=0;
						}
					}
				}
				else if(in.isKeyDown(Input.KEY_LEFT)){
					direction = 3;
					di = 3;
					this.animation=game.Multiplayer.movingLeft[this.id];
					this.animation.start();
					if(this.position[0]-this.speed*delta>0){

						if(game.Multiplayer.map.field[Math.round(this.position[1])][(int)Math.floor(this.position[0]-this.speed*delta)].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("left", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[0]-=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("left", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])-1].speedx=-0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])-1].speedy=0;
						}
					}

				}

				else if(in.isKeyDown(Input.KEY_UP)){
					direction = 0;
					di = 0;
					this.animation=game.Multiplayer.movingUp[this.id];
					this.animation.start();
					if(this.position[1]-this.speed*delta>0){
						if(game.Multiplayer.map.field[(int) Math.floor(this.position[1]-this.speed*delta)][Math.round(this.position[0])].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("up", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[1]-=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("up", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])-1][Math.round(this.position[0])].speedy=-0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])-1][Math.round(this.position[0])].speedx=0;
						}
					}
				}

				else if(in.isKeyDown(Input.KEY_DOWN)){
					direction = 1;
					di = 1;
					this.animation=game.Multiplayer.movingDown[this.id];
					this.animation.start();
					if(this.position[1]+this.speed*delta<game.Multiplayer.map.size-1){
						if(game.Multiplayer.map.field[(int) Math.ceil(this.position[1]+this.speed*delta)][Math.round(this.position[0])].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("down", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[1]+=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("down", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])+1][Math.round(this.position[0])].speedy=+0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])+1][Math.round(this.position[0])].speedx=0;
						}
					}
				}
				else{
					direction = 4;
					this.animation.stop();
					this.animation.setCurrentFrame(0);
				}

				if(in.isKeyPressed(Input.KEY_ENTER)){
					direction = 5;
					this.setBomb();
				}
			}

		}
		else if(id==2){
			if(this.lifes>=0){

				if(in.isKeyDown(Input.KEY_D)){
					this.animation=game.Multiplayer.movingRight[this.id];
					this.animation.start();
					if( this.position[0]+this.speed*delta<game.Multiplayer.map.size-1){ 

						if(game.Multiplayer.map.field[Math.round(this.position[1])][(int)Math.ceil(this.position[0]+this.speed*delta)].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("right", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[0]+=this.speed*delta;
						}

						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("right", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])+1].speedx=0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])+1].speedy=0;
						}
					}
				}
				else if(in.isKeyDown(Input.KEY_A)){
					this.animation=game.Multiplayer.movingLeft[this.id];
					this.animation.start();
					if(this.position[0]-this.speed*delta>0){

						if(game.Multiplayer.map.field[Math.round(this.position[1])][(int)Math.floor(this.position[0]-this.speed*delta)].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("left", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[0]-=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("left", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])-1].speedx=-0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])-1].speedy=0;
						}
					}

				}

				else if(in.isKeyDown(Input.KEY_W)){
					this.animation=game.Multiplayer.movingUp[this.id];
					this.animation.start();
					if(this.position[1]-this.speed*delta>0){
						if(game.Multiplayer.map.field[(int) Math.floor(this.position[1]-this.speed*delta)][Math.round(this.position[0])].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("up", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[1]-=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("up", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])-1][Math.round(this.position[0])].speedy=-0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])-1][Math.round(this.position[0])].speedx=0;
						}
					}
				}

				else if(in.isKeyDown(Input.KEY_S)){
					this.animation=game.Multiplayer.movingDown[this.id];
					this.animation.start();
					if(this.position[1]+this.speed*delta<game.Multiplayer.map.size-1){
						if(game.Multiplayer.map.field[(int) Math.ceil(this.position[1]+this.speed*delta)][Math.round(this.position[0])].walk
								||(
										game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("bomb") &&
										nextFieldType("down", Math.round(this.position[0]) , Math.round(this.position[1]), "space")
										))
						{
							this.position[1]+=this.speed*delta;
						}
						//kicken
						else if(game.Multiplayer.map.field[Math.round(this.position[1])][Math.round(this.position[0])].type.equals("space") &&
								nextFieldType("down", Math.round(this.position[0]) , Math.round(this.position[1]), "bomb") &&
								this.kick)
						{
							game.Multiplayer.map.field[Math.round(this.position[1])+1][Math.round(this.position[0])].speedy=+0.007f;
							game.Multiplayer.map.field[Math.round(this.position[1])+1][Math.round(this.position[0])].speedx=0;
						}
					}
				}
				else{
					this.animation.stop();
					this.animation.setCurrentFrame(0);
				}

				if(in.isKeyPressed(Input.KEY_SPACE)){
					this.setBomb();
				}
			}
		}
	}

	/**
	 * Checks the next field if its walkable
	 * @param s Gives the direction
	 * @param x	X-Position if the player
	 * @param y Y-Position of the player
	 * @return Returns true if next field is walkable
	 */
	public static boolean nextFieldWalkable(String s, int x, int y){
		if(s.equals("right")){

			if(x==game.Multiplayer.map.size-1){
				return false;
			}
			else{
				return game.Multiplayer.map.field[y][x+1].walk ;
			}

		}
		else if(s.equals("left")){
			if(x==0){
				return false;
			}
			else{
				return game.Multiplayer.map.field[y][x-1].walk ;
			}

		}
		else if(s.equals("up")){
			if(y==0){
				return false;
			}
			else{
				return game.Multiplayer.map.field[y-1][x].walk ;
			}
		}
		else if(s.equals("down")){
			if(y==game.Multiplayer.map.size-1){
				return false;
			}
			else{
				return game.Multiplayer.map.field[y+1][x].walk ;
			}

		}
		else{return false;}
	}

	/**
	 * Checks if the next field is the transmitted type
	 * @param s Gives the direction
	 * @param x	X-Position if the player
	 * @param y Y-Position of the player
	 * @param t The transmitted field type
	 * @return Returns true if the next field is the transmitted type
	 */
	public static boolean nextFieldType(String s, int x, int y, String t){
		if(s.equals("right")){
			if(x==game.Multiplayer.map.size-1){
				return false;
			}
			else{
				return game.Multiplayer.map.field[y][x+1].type.equals(t);
			}

		}
		else if(s.equals("left")){
			if(x==0){
				return false;
			}
			else{
				return game.Multiplayer.map.field[y][x-1].type.equals(t) ;
			}

		}
		else if(s.equals("up")){
			if(y==0){
				return false;
			}
			else{
				return game.Multiplayer.map.field[y-1][x].type.equals(t) ;
			}
		}
		else if(s.equals("down")){
			if(y==game.Multiplayer.map.size-1){
				return false;
			}
			else{
				return game.Multiplayer.map.field[y+1][x].type.equals(t) ;
			}

		}
		else{return false;}
	}

	public void animationPlayer(){
		if(direction == 0){
			this.animation=game.Multiplayer.movingUp[this.id];
			this.animation.start();
		}else if(direction == 1){
			this.animation=game.Multiplayer.movingDown[this.id];
			this.animation.start();
		}else if(direction == 2){
			this.animation=game.Multiplayer.movingRight[this.id];
			this.animation.start();
		}else if(direction == 3){
			this.animation=game.Multiplayer.movingLeft[this.id];
			this.animation.start();
		}else if(direction == 4 ) {
			if(di == 0){
				this.animation=game.Multiplayer.movingUp[this.id];
				this.animation.start();
				this.animation.stop();
				this.animation.setCurrentFrame(0);}
			else if(di == 1){
				this.animation=game.Multiplayer.movingDown[this.id];
				this.animation.start();
				this.animation.stop();
				this.animation.setCurrentFrame(0);}
			else if(di == 2){
				this.animation=game.Multiplayer.movingRight[this.id];
				this.animation.start();
				this.animation.stop();
				this.animation.setCurrentFrame(0);}
			else if(di == 3){
				this.animation=game.Multiplayer.movingLeft[this.id];
				this.animation.start();
				this.animation.stop();
				this.animation.setCurrentFrame(0);}
		}
	}
}
